import { get } from '@/utils/http'
import Toast from '@vant/weapp/toast/toast'
import Dialog from '@vant/weapp/dialog/dialog'
Component({
  properties: {
    cid: Number,
    code: Number
  },
  data: {

  },
  methods: {
    goPlay(){
      Dialog.confirm({
        context: this,
        title: '支付',
        message: '您即将前往支付，确认吗?',
      }).then(() => {
        get('/order/pay',{
          order_id: this.properties.cid
        }).then(res =>{
          if (res.result) {
            Toast.success({ message:'支付成功，将回到订单页', context: this })
            let timer = setTimeout(() => {
              clearTimeout(timer)
              wx.reLaunch({ url: "/pages/indent/index" })
            },1000)
          } else  Toast.fail({ message:'支付失败', context: this })
        })
        }).catch(() => {
          Toast.fail({ message:'支付取消', context: this })
        });
    },
    goOut() {
      Dialog.confirm({
        context: this,
        title: '取消订单',
        message: '您即将取消当前订单，确认吗?',
      }).then(() => {
        get('/order/cancel',{
          order_id: this.properties.cid
        }).then(res =>{
          if (res.result) {
            Toast.success({ message:'取消成功，将回到订单页', context: this })
            let timer = setTimeout(() => {
              clearTimeout(timer)
              wx.reLaunch({ url: "/pages/indent/index" })
            },1000)
          } else  Toast.fail({ message:'取消失败', context: this })
        })
        }).catch(() => {
          Toast.fail({ message:'取消订单取消', context: this })
        });
    },
    goRefund() {
      Dialog.confirm({
        context: this,
        title: '取消订单',
        message: '您确定申请退款吗?',
      }).then(() => {
        get('/order/cancel',{
          order_id: this.properties.cid
        }).then(res =>{
          if (res.result) {
            Toast.success({ message:'申请成功，将回到订单页', context: this })
            let timer = setTimeout(() => {
              clearTimeout(timer)
              wx.reLaunch({ url: "/pages/indent/index" })
            },1000)
          } else  Toast.fail({ message:'申请失败，请与商家联系', context: this })
        })
        }).catch(() => {
          Toast.fail({ message:'申请取消', context: this })
        });
    }
  }
})